package com.stox.services.watchlist.manager.impl;

import java.util.List;

import com.stox.services.watchlist.manager.WatchlistEntryManager;
import com.stox.services.watchlist.manager.WatchlistManager;
import com.stox.services.watchlist.repository.WatchlistRepository;
import com.stox.shared.watchlist.model.Watchlist;
import com.stox.shared.watchlist.model.WatchlistEntry;

public class WatchlistManagerImpl implements WatchlistManager {
	
	public static final WatchlistManagerImpl INSTANCE = new WatchlistManagerImpl();
	
	private WatchlistManagerImpl() {
		
	}

	@Override
	public List<Watchlist> findAll() {
		return WatchlistRepository.INSTANCE.findAll();
	}

	@Override
	public Long saveOrUpdate(Watchlist watchlist) {
		return WatchlistRepository.INSTANCE.saveOrUpdate(watchlist);
	}

	@Override
	public void delete(Long id) {
		WatchlistRepository.INSTANCE.delete(id);
		List<WatchlistEntry> watchlistEntries = WatchlistEntryManager.INSTANCE.findByWatchlistId(id);
		for(WatchlistEntry watchlistEntry : watchlistEntries){
			WatchlistEntryManager.INSTANCE.delete(watchlistEntry.getId());
		}
	}

}
